import { defineStore } from 'pinia'
import { UpdateUserData, UserInfo, UserStoreType } from '@/store/modules/interface/user'

export const useUserInfoStore = defineStore('userInfoStore', {
	state: (): UserStoreType => {
		return {
			userInfo: {
				_id: '', //id
				phone: '', //手机号
				token: '', //token
				nick: '', //昵称
				imgUrl: '', //头像
				sex: '', //性别
				birthday: '', //生日
				start: '',
				sign: ''
			}
		}
	},
	actions: {
		login(userInfo: UserInfo) {
			this.userInfo = userInfo
		},
		logout() {
			this.userInfo = {
				_id: '', //id
				phone: '', //手机号
				token: '', //token
				nick: '', //昵称
				imgUrl: '', //头像
				sex: '', //性别
				birthday: '', //生日
				start: '',
				sign: ''
			}
		},
		updateInfo(data: UpdateUserData) {
			const { nick, sex, imgUrl, birthday, start, sign } = data
			this.userInfo.nick = nick
			this.userInfo.sex = sex
			this.userInfo.imgUrl = imgUrl
			this.userInfo.birthday = birthday
			this.userInfo.start = start as string
			this.userInfo.sign = sign
		}
	}
})
